package com.boxuegu.boxueguapiservice.controller;


import com.boxuegu.boxueguapiservice.entity.Course;
import com.boxuegu.boxueguapiservice.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Vincent
 */
@RestController
@RequestMapping("/course")
public class CourseController {
  @Autowired
  private CourseService courseService;
  
  /**
   * 查询课程列表
   * @return 返回结果集
   */
  @PostMapping("/findCourseAll")
  @ResponseBody
  public Map<String, Object> findCourseAll() {
    Map<String, Object> map = new HashMap<>();
    List<Course> courseList = courseService.findCourseAll();
    if (courseList != null) {
      map.put("msg", "成功");
      map.put("success", true);
      map.put("courseList", courseList);
    } else {
      map.put("msg", "失败");
      map.put("success", false);
    }
    return map;
  }
  
  /**
   * 根据章节号,查询章节介绍
   * @param param 章节id chapterId
   * @return 返回章节信息
   */
  @PostMapping("/findCourseByChapterId")
  @ResponseBody
  public Map<String, Object> findCourseByChapterId(@RequestBody Map<String,Object> param) {
    Map<String, Object> map = new HashMap<>();
    int chapterId = (int) param.get("chapterId");
    List<Course> courseList = courseService.findCourseByChapterId(chapterId);
    if (courseList != null) {
      map.put("msg", "成功");
      map.put("success", true);
      map.put("courseList", courseList);
    } else {
      map.put("msg", "失败");
      map.put("success", false);
    }
    return map;
  }
}
